// JavaScript Document
function bitAdd(){
	 $("#BitContent").append(
	 "<div class='patternItem'>"
	 +	"<div id='pattern_title' class='SubItemTitle'>"
	 +		"<div class='patternLeft'>Add Bit Item</div>"
	 +      "<div class='patternRight'>"
	 + 			"<a href='#' class='rangeRemove' onclick='bitDelete(this)' ><img class='buttonBcImg' width='20' src='./images/delete.png' /></a>  "
	 +			"<a href='#' class='rangeAdd' onclick='bitAdd()' ><img class='buttonBcImg' width='20' src='./images/add.png'/></a>"
	 +		"</div>"
	 +		"<div style='clear:both;'></div>"
	 +	"</div><!--  pattern_title end -->"
	 +	"<!-- ******************************************************************* --> "
	 +	"<div id='BitItemContainer' class='SubItemSContainer' >"
	 +		"<div class='itemDiv'>"
	 +			"<span class='textSpan'>&nbsp;Bit name:</span>"
	 +			"<input class='inputText' id='bitItem_name' name='bitItem_name' value=''  />"
	 +			"<span class='notNullSpan'>(*String)</span>"
	 +		"</div>"
	 +		"<div class='itemDiv'>"
	 +			"<span class='textSpan'>&nbsp;Position:</span>"
	 +			"<input class='inputText' id='bitItem_position' name='bitItem_position' value=''  />"
	 +			"<span class='notNullSpan'>(*Integer)</span>"
	 +		"</div>"
	 +		"<div class='itemDiv'>"
	 +			"<span class='textSpan'>&nbsp;Status:</span>"
	 +			"<select style='width:305px;   height:23px;'   class='inputSelect' id='bitItem_status' name='bitItem_status'>"
	 +				getStatus()
	 +			"</select>"
	 +		"</div>"
	 +		"<span class='textSpan'>&nbsp;Description:</span><br/>"
	 +		"<textarea class='intextArea'  id='bitItem_description' name='bitItem_description'></textarea>"
	 +		"<span class='textSpan'>&nbsp;Reference:</span><br/>"
	 +		"<textarea class='intextArea'  id='bitItem_reference' name='bitItem_reference'></textarea>"
	 +	"</div>"
     +"</div>"
	 );
	 $("input#B_bitAdd").hide();
}

function getStatus(){
	var StatusList = StatusArr.split("_"); 
	var optionsStr = "";
	for(i = 0 ; i < StatusList.length ; i++ ){
		optionsStr += "<option  value='"+StatusList[i]+"' >"+StatusList[i]+"</option>"
	}
	return optionsStr
}

function bitDelete(obj){
    $(obj).parent().parent().parent().remove();
    //兼容 IE and Firefox  sdf
    if( $("div#BitContent").html().trim().length == 0){$("input#B_bitAdd").show();}
}
/**
*  bitItem_name[pos]bitItem_position[sta]bitItem_status[des]bitItem_description[ref]bitItem_reference
*  [bitItem]
*  bitItem_name[pos]bitItem_position[sta]bitItem_status[des]bitItem_description[ref]bitItem_reference
*  [bitItem]
*  .....
*/
function getBitsStr(){
	var bitItem_name        = document.getElementsByName("bitItem_name");
	var bitItem_position    = document.getElementsByName("bitItem_position");
	var bitItem_status      = document.getElementsByName("bitItem_status");
	var bitItem_description = document.getElementsByName("bitItem_description");
	var bitItem_reference   = document.getElementsByName("bitItem_reference");
	var bitItem_ParamStr    = "";
	$("input.inputText").css("border-color","");
	for(i = 0 ; i < bitItem_name.length ; i++){
		if("" == bitItem_name[i].value ){
			alert("Bit name can't be empty!");
			$(bitItem_name[i]).css("border-color","red");
			$(bitItem_name[i]).focus();
			return false;
		}
		if("" == bitItem_position[i].value || isNaN(bitItem_position[i].value)){
			alert("Enter numbers!");
			$(bitItem_position[i]).css("border-color","red");
			$(bitItem_position[i]).focus();
			return false;
		}
		bitItem_ParamStr += bitItem_name[i].value;
		bitItem_ParamStr += "[pos]" +  bitItem_position[i].value;
		bitItem_ParamStr += (("" == bitItem_status[i].value)?"":"[sta]"+bitItem_status[i].value);
		bitItem_ParamStr += (("" == bitItem_description[i].value)?"":"[des]"+bitItem_description[i].value);
		bitItem_ParamStr += (("" == bitItem_reference[i].value)?"":"[ref]"+bitItem_reference[i].value);
		
		//最后一个不需要加分隔符
		if(i != bitItem_name.length -1){
			bitItem_ParamStr += "[bitItem]";
		}
	}
	document.getElementById("bits_para").value = bitItem_ParamStr;
	//alert(bitItem_ParamStr);
	if("" == bitItem_ParamStr){
		alert("bits can not be empty!");
		return false;
	}
	return true;
}


